package rule20;

import rule20.validatecode.processor.ImageCodeProcessor;
import rule20.validatecode.processor.SmsCodeProcessor;
import rule20.validatecode.processor.ValidateCodeProcessor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ChangLiang
 * @date 2020/4/15
 */
public class ValidateCodeProcessorHolder {

    private static Map<String, ValidateCodeProcessor> validateCodeProcessorMap;

    static{
        validateCodeProcessorMap = new HashMap<>(2);
        validateCodeProcessorMap.put("imageValidateCodeProcessor", new ImageCodeProcessor());
        validateCodeProcessorMap.put("smsValidateCodeProcessor", new SmsCodeProcessor());
    }

    public ValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type) {
        return findValidateCodeProcessor(type.toString());
    }

    public ValidateCodeProcessor findValidateCodeProcessor(String type) {
        String beanName = type.toLowerCase() + ValidateCodeProcessor.class.getSimpleName();
        ValidateCodeProcessor validateCodeProcessor = validateCodeProcessorMap.get(beanName);
        return validateCodeProcessor;
    }
}
